/*
** my_getnbr.c for my_getnbr in /home/chassa_m/rendu/Piscine-C-lib/my
** 
** Made by chassa_m
** Login   <chassa_m@epitech.net>
** 
** Started on  Tue Oct  8 13:13:07 2013 chassa_m
** Last update Mon Oct 28 12:39:27 2013 chassa_m
*/

int     is_neg(char *str)
{
  int   i;
  int   counter;

  i = 0;
  counter = 0;
  while (str[i] > '9' || str[i] < '0')
    {
      if (str[i] == '-')
        counter = counter + 1;
      i = i + 1;
    }
  if (counter % 2 != 0)
    return (1);
  else
    return (0);
}

int     is_num(char l)
{
  if (l >= '0' && l <= '9')
    return (1);
  else
    return (0);
}

int     my_getnbr(char *str)
{
  int   i;
  int   nbr;

  nbr = 0;
  i = 0;
  while (is_num(str[i]) == 0)
    i = i + 1;
  while (is_num(str[i]) == 1)
    {
      nbr = ((nbr * 10) + (str[i] - 48));
      i = i + 1;
    }
  if (is_neg(str) == 1)
    nbr = -nbr;
  return (nbr);
}
